var jump = document.querySelector(".jump");
jump.addEventListener("animationend", function(){
	jump.classList.add("pulse");
	jump.style.animation = "pulse 1.5s infinite";
})
var lis = document.querySelectorAll("li");
//加载中
function loadUl(){
	var r = 0;
	setInterval(function(){
		for(i=0;i<lis.length;i++){
			lis[i].style.display = "none";
		}
		if(r==(lis.length-1)){
			console.log(22);
			lis[r].style.display = "block";
			r = 0;
		}else if(r<lis.length){
			lis[r].style.display = "block";
			r++;
		}
	},600)
}
loadUl();
//ajax请求歌曲
let xhr = new XMLHttpRequest();
xhr.open("get","./json/music.json");
xhr.send();
xhr.addEventListener("readystatechange",function(){
	if(xhr.status == 200&&xhr.readyState == 4){
		var result = JSON.parse(xhr.responseText);
		console.log(result,typeof result);
		fun(result);
	}
})
var res = [];
//遍历对象
var fun = function Traversing(obj){
	for(i=0;i<obj.length;i++){
		res.push(obj[i].audio);
	}
//	console.log(res);
	//随机生成二十首歌
	var num = [];
	var res1 = [];
	var music = [];
	for(j=0;;j++){
		var ran = Math.floor(Math.random()*51);
		console.log()
		if(num.length==0){
			num.push(ran);
		}else if(num.length==20){
			break;
		}else if(num.indexOf(ran)==-1){
			num.push(ran);
		}else{
			console.log(1)
		}
//		res1.push(res[ran]);
//		music.push(obj[ran]);
		
	}
	console.log(num);
	for(i=0;i<num.length;i++){
		res1.push(res[num[i]]);
		music.push(obj[num[i]]);
	}
	console.log(res1);
	console.log(music);
	load(res1);
	music = JSON.stringify(music);
	sessionStorage.setItem("Arr",music);
	console.log("Arr");
}
var arr = [];
//预加载
function load(obj){
	var queue = new createjs.LoadQueue();	
	for(i=0;i<20;i++){
		var x = {"id":i,"src":obj[i]};
		arr.push(x);
	}
	let song = JSON.stringify(arr);
	console.log(arr);
	queue.loadManifest(arr);
	queue.on("progress",function(res){
		console.log("progress:",res);
		jump.classList.remove("pulse");
		jump.classList.remove("bounceInLeft");
	})
	queue.on("complete",function(res){
		jump.style.display = "block";
		for(i=0;i<lis.length;i++){
			lis[i].innerText = "加载完成";
		}
		sessionStorage.setItem("arr",song);
	})
}

